package com.xbongbong.paas.domain.entity;

import com.alibaba.fastjson.JSONArray;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.paas.toolbox.wrap.Entity;
import com.xbongbong.paas.toolbox.wrap.QueryIgnore;
import com.xbongbong.sys.domain.entity.MirrorCompanyEntity;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * 阶段流程实体
 * @author 李少杰
 * @version v1.0.0
 * @date 2021/11/17 09:26
 */
@Setter
@Getter
@ToString
public class StageProcessEntity extends Entity {

    /**
     * 主键
     */
    private Long id;
    /**
     * 公司id
     */
    private String corpid;
    /**
     * 表单id
     */
    private Long formId;
    /**
     * 流程名称
     */
    private String name;
    /**
     * 阶段流程版本名称
     */
    private String versionName;
    /**
     * 阶段流程版本id
     */
    private Integer versionId;
    /**
     * 是否启用，1启用，0不启用
     */
    private Integer enable;
    /**
     * 阶段停留单位【1时、2天、3周、4月】
     */
    private Integer stageUnit;
    /**
     * 允许回退阶段（0不允许、1允许）
     */
    private Integer allowBack;
    /**
     * 允许新建选择阶段（0不允许、1允许）
     */
    private Integer allowNewSelect;
    /**
     * 哪些人允许新建选择阶段，空值代表所有人都允许
     */
    private JSONArray allowNewSelectUser;
    /**
     * 阶段用时（0不显示、1显示）
     */
    private Integer showTimeUse;
    /**
     * 阶段停留时长（0不显示、1显示）
     */
    private Integer showTimeStay;
    /**
     * 任务完成情况（0不显示、1显示）
     */
    private Integer showWorkCompletion;
    /**
     * 公司平均完成时长（0不显示、1显示）
     */
    private Integer showAverageCompletionTime;
    /**
     * 触发条件
     */
    private JSONArray triggerCondition;
    /**
     * 1：归档、2：未归档
     */
    private Integer isArchive;
    /**
     * 创建者id
     */
    private String creatorId;
    /**
     * 是否历史数据迁移过来时最早默认生成的流程版本
     */
    private Integer oldTransferVersion;
    /**
     * 优先级字段，数值越小优先级越高
     */
    private Integer priority;
    /**
     * 镜像阶段流程id(镜像应用复制时使用)
     */
    @Getter(onMethod_ = {@QueryIgnore})
    private Long mirrorStageProcessId;
    /**
     * 创建时间时间戳
     */
    private Long addTime;
    /**
     * 更新时间时间戳
     */
    private Long updateTime;
    /**
     * 删除标记
     */
    private Integer del;

    /**
     * 显式构造器
     */
    public StageProcessEntity() {
        del = 0;
    }

    public StageProcessEntity(String corpid, Long formId, String name, String versionName, Integer versionId, Integer enable, Integer stageUnit, Integer allowBack, Integer allowNewSelect, JSONArray allowNewSelectUser, Integer showTimeUse, Integer showTimeStay, Integer showWorkCompletion, Integer showAverageCompletionTime, JSONArray triggerCondition, Integer isArchive, String creatorId, Integer oldTransferVersion, Integer del) {
        this.corpid = corpid;
        this.formId = formId;
        this.name = name;
        this.versionName = versionName;
        this.versionId = versionId;
        this.enable = enable;
        this.stageUnit = stageUnit;
        this.allowBack = allowBack;
        this.allowNewSelect = allowNewSelect;
        this.allowNewSelectUser = allowNewSelectUser;
        this.showTimeUse = showTimeUse;
        this.showTimeStay = showTimeStay;
        this.showWorkCompletion = showWorkCompletion;
        this.showAverageCompletionTime = showAverageCompletionTime;
        this.triggerCondition = triggerCondition;
        this.isArchive = isArchive;
        this.creatorId = creatorId;
        this.oldTransferVersion = oldTransferVersion;
        this.del = del;
        this.addTime = DateTimeUtil.getInt();
        this.updateTime = DateTimeUtil.getInt();
    }
    /**
     * 生成初始化的流程版本
     *
     * @param corpid    公司id
     * @param formId    表单id
     * @param allowBack 是否允许回退
     */
    public void initStageProcess(String corpid, Long formId, Integer allowBack, Integer oldTransferVersion) {
        this.corpid = corpid;
        this.formId = formId;
        this.name = "默认阶段流程";
        this.versionName = "v1";
        this.versionId = 1;
        this.enable = 1;
        this.stageUnit = 1;
        this.allowBack = allowBack;
        this.allowNewSelect = 1;
        this.showTimeUse = 1;
        this.showTimeStay = 1;
        this.showWorkCompletion = 1;
        this.showAverageCompletionTime = 0;
        this.isArchive = 2;
        this.oldTransferVersion = oldTransferVersion;
        this.priority = 1;
        this.addTime = DateTimeUtil.getInt();
        this.updateTime = DateTimeUtil.getInt();
        this.del = 0;
    }
}
